package com.wl.dzt.sys.core.dao.curd.sql.el;

import com.wl.dzt.sys.core.dao.select.term.Term;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wl_code@163.com
 * @date 2018/7/5/005
 * @version 1.0
 * @description sql表格参数
 * 
 */
public class SqlParam {
	/**
	 * sql语句
	 */
	private String sql;

	/**
	 * 开始页
	 */
	private int start = 0;

	/**
	 * 往后取多少条
	 */
	private int limit = -1;

	/**
	 * 查询条件
	 */
	private List<Term> terms = new ArrayList<>();

	/**
	 * 完整的sql
	 */
	private String fullSql;

	/***
	 * 
	 * <b>注意</b>
	 * <p>
	 * 使用SqlParamBuilder 来构建该类实例
	 * </p>
	 * 
	 * @param sql
	 */
	@Deprecated
	public SqlParam(String sql) {
		this.sql = sql;
	}

	public void setFullSql(String fullSql) {
		this.fullSql = fullSql;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public List<Term> getTerms() {
		return terms;
	}

	public void setTerms(List<Term> terms) {
		this.terms = terms;
	}

	public String getFullSql() {
		return fullSql;
	}

	/**
	 * 
	 * <b>总数sql</b>
	 * <p>
	 * 获取当前sql的总数查询语句
	 * </p>
	 * 
	 * @return sql
	 */
	public String countSql() {
		return "select count(0) as count  from ( " + this.fullSql + " )  dzt_table";
	}
}
